package modules.evaluator;

import com.beust.jcommander.JCommander;

import miscellaneous.JCommanderUsageWrapper;
import modules.HomoCompara;
import modules.scripts.Scripts;

public class Evaluator implements HomoCompara {

	public String getModuleName() {
		return "evaluator";
	}

	public void main(String[] args) throws Exception {
		Parameters params;
		String path;
		String output;
		
		boolean apbEvaluation;
		String clusterFile;
		boolean simulatedData;
		String testFile;
		boolean yeast;
		String software;
		String testFileinBCLFormat;

		 try {

			 // ================ PARSE USER OPTIONS AND ARGUMENTS ================

			 params = new Parameters();
			 JCommander jc = new JCommander(params, args);

			 if (args.length == 0 || params.help) {
				 StringBuilder sb = new StringBuilder(65536);
				 sb.append(
						 "================================================================================\n" +
								 "evaluator is ........... \n\n" +
								 "If you use this program in your research or for comparison reasons, please cite the \n" +
								 "following articles.\n" +
								 "References:\n" +
								 "    HomoCompara : A Comparative Study of Homology Inference Techniques and Methodologies \n" +
								 "    on Eukaryotic, Fungi, Bacteria and Simulated Datasets,\n" +
								 "    Ali RH, Muhammad SA and Lars Arvestad, 2014, doi: .................\n\n" +
								 "Releases, source code and tutorial: http://code.google.com/p/homocompara/\n\n" +
								 "License: GenFamClust is available under the New BSD License.\n" +
						 "================================================================================\n");
				 sb.append("Usage:\n" +
						 "    java -jar evaluator-X.Y.Z.jar hcluster [options] <args>\n");
				 JCommanderUsageWrapper.getUnsortedUsage(jc, params, sb);
				 System.out.println(sb.toString());
				 return;
			 }

			 path = params.path;
			 output = params.output;
			 apbEvaluation = params.apbEvaluation;
			 clusterFile = params.files.get(0);
			 simulatedData = params.simulatedData;
			 testFile = params.testFile;
			 yeast = params.yeast;
			 software = params.software;
			 testFileinBCLFormat = params.testFileinBCLFormat;

			 if(!path.endsWith("/"))
				 path = path.concat("/");
			 
			 if(testFile.equals("")) {
			 } else {
				 if(!params.graphicalCluster) {
					 Scripts.ClusterSeparator(path, testFile, clusterFile, output);
				 }
				 else {
					 Scripts.ClusterSeparatorFromgraphicsFile(path, testFile, clusterFile, "temp" + output);
					 Scripts.ClusterSeparator(path, testFile, "temp" + output, output);
				 }
				 if(simulatedData) {
					 SimulatedDatasetEvaluator sde = new SimulatedDatasetEvaluator();
					 sde.qualityEvaluator(testFileinBCLFormat, path, output + ".qua", software, output + "_Fam.bcl");
					 sde.recallEvaluator(testFileinBCLFormat, path, output + ".qua", software, output + "_Fam.bcl");
					 sde.precisionEvaluator(testFileinBCLFormat, path, output + ".qua", software, output + "_Fam.bcl");
				 } else if(apbEvaluation) {
					 
				 } else if (yeast) {
					 
				 } else {
					 MultiSpecEvaluator mse = new MultiSpecEvaluator();
					 if(!params.kinase) {
						 mse.precisionEvaluator(path, output + ".qua", software, output + "_Fam.bcl");
						 mse.recallEvaluator(path, output + ".qua", software, output + "_Fam.bcl");
						 mse.qualityEvaluator(path, output + ".qua", software, output + "_Fam.bcl");
					 } else {
						mse.precisionEvaluatorWithoutKinase(path, output + ".qua", software, output + "_Fam.bcl");
						mse.recallEvaluatorWithoutKinase(path, output + ".qua", software, output + "_Fam.bcl");
						mse.qualityEvaluatorWithoutKinase(path, output + ".qua", software, output + "_Fam.bcl");
					 }
				 }
			 }

		 } catch (Exception e) {
			 System.out.println("Data Preparator Failed : " + e.getMessage());
			 System.exit(-1);
		 }		
	}

}
